<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>矩形的绘制</title>
    <script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.14&key=cee005f5ef04df4d58c24345425ec3ff"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body,
        #container {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div id="container"></div>
    <script>
        var map = new AMap.Map('container', {
            center: [116.397637, 39.900001],
            zoom: 14
        });
        var southWest = new AMap.LngLat(116.356449, 39.859008)
        var northEast = new AMap.LngLat(116.417901, 39.893797)

        var bounds = new AMap.Bounds(southWest, northEast)

        var rectangle = new AMap.Rectangle({
            bounds: bounds,
            strokeColor: 'red',
            strokeWeight: 6,
            strokeOpacity: 0.5,
            strokeDasharray: [30, 10],
            // strokeStyle还支持 solid
            strokeStyle: 'dashed',
            fillColor: 'blue',
            fillOpacity: 0.5,
            cursor: 'pointer',
            zIndex: 50,
        })

        rectangle.setMap(map)
        // 缩放地图到合适的视野级别
        map.setFitView([rectangle])
    </script>
</body>

</html>